package com.ruoyi.psi.base.warehouse.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.psi.base.warehouse.domain.*;
import com.ruoyi.psi.base.warehouse.service.IWarehouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 仓库信息
 * 视图层
 */
@RestController
@RequestMapping("/psi/base/warehouse")
@Api(value = "仓库信息模块", tags = "仓库信息接口")
public class WarehouseController extends BaseController {
    @Autowired
    private IWarehouseService warehouseService;

    /**
     * 获取仓库列表
     * @param cond
     * @return
     */
    @ApiOperation(value = "获取仓库列表",notes = "查询所有仓库信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody WarehouseCond cond){
        startPage();
        List<WarehouseDto> warehouseDtos = warehouseService.selectWarehouseList(cond);
        return getDataTable(warehouseDtos);
    }

    /**
     * 导出仓库
     * @param cond
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody WarehouseCond cond) {
        List<WarehouseDto> warehouseDtos = warehouseService.selectWarehouseList(cond);
        ExcelUtil<WarehouseDto> util = new ExcelUtil<>(WarehouseDto.class);
        return util.exportExcel(warehouseDtos, "仓库数据");
    }

    /**
     * 新增仓库
     * @param warehouse
     * @return
     */
    @ApiOperation(value = "新增仓库", notes = "新增仓库")
    @ApiImplicitParam(name = "warehouse", value = "新增仓库", dataType = "WarehouseDomain")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody WarehouseDomain warehouse) {
        return toAjax(warehouseService.insertWarehouse(warehouse));
    }

    /**
     * 修改仓库
     * @param warehouse
     * @return
     */
    @ApiOperation(value = "修改仓库", notes = "修改仓库")
    @ApiImplicitParam(name = "warehouse", value = "修改仓库", dataType = "WarehouseDomain")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody WarehouseDomain warehouse) {
        return toAjax(warehouseService.updateWarehouse(warehouse));
    }

    /**
     * 仓库详细更新
     * @param warehouseList
     * @return
     */
    @ApiOperation(value = "修改仓库详情", notes = "修改仓库详情")
    @ApiImplicitParam(name = "warehouseList", value = "修改仓库详情", dataType = "WarehouseListDomain")
    @PostMapping("/updateWarehouseList")
    public AjaxResult updateWarehouseList(@RequestBody WarehouseListDomain warehouseList) {
        return toAjax(warehouseService.updateWarehouseList(warehouseList));
    }

    /**
     * 删除仓库
     * 仅修改删除标志位
     * @param warehouse
     * @return
     */
    @PostMapping("/delete")
    @ApiOperation(value = "删除仓库", notes = "删除仓库")
    public AjaxResult delete(@RequestBody WarehouseDomain warehouse) {
        return toAjax(warehouseService.updateWarehouseDeleteFlag(warehouse));
    }

    @GetMapping("/product")
    @ApiOperation(value = "查询指定仓库的所有产品信息", notes = "查询指定仓库的所有产品信息")
    public TableDataInfo selectWarehouseListListById(@RequestParam String warehouseId) {
        startPage();
        List<WarehouseListDto> warehouseListDtos = warehouseService.selectWarehouseListListById(warehouseId);
        return getDataTable(warehouseListDtos);
    }
}
